package com.yanqu.road.entity.activity.shushan.config;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.shushan.eShuShanBuildType;
import com.yanqu.road.entity.enums.eActivityConfigType;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description 蜀山配置
 * @Author cwq
 * @Data 2022/3/8 11:45
 */
public class ShuShanActivityConfig {

    private static final String SHUSHAN_SECT_NAME = "SHUSHAN_SECT_NAME_";

    private List<ShuShanBuildConfig> buildConfigList = new ArrayList<>();
    private Map<Integer, ShuShanBuildConfig> buildConfigMap = new ConcurrentHashMap<>();
    /**
     * k: type k:等级 v:配置
     */
    private Map<Integer, Map<Integer, ShuShanBuildConfig>> typeLevelBuildMap = new ConcurrentHashMap<>();
    /**
     * k: type k:等级 v:配置
     */
    private Map<Integer, List<ShuShanBuildConfig>> typeLevelBuildListMap = new ConcurrentHashMap<>();
    /**
     * k: type k:等级 v:技能id
     */
    private Map<Integer, List<Integer>> typeLevelSkillListMap = new ConcurrentHashMap<>();

    private List<ShuShanSkillConfig> skillConfigList = new ArrayList<>();
    private Map<Integer, ShuShanSkillConfig> skillConfigMap = new ConcurrentHashMap<>();
    /**
     * 技能类型 配置集合  k:技能类型 v:对应的技能
     */
    private Map<Integer, List<ShuShanSkillConfig>> skillTypeConfigMap = new ConcurrentHashMap<>();
    /**
     * k:技能大类 k技能小类 k:技能等级，
     */
    private Map<Integer, Map<Integer, Map<Integer, ShuShanSkillConfig>>> typeLevelConfigMap = new ConcurrentHashMap<>();
    /**
     * k:技能大类 k技能小类 k:技能等级，
     */
    private Map<Integer, Map<Integer, List<ShuShanSkillConfig>>> typeLevelConfigListMap = new ConcurrentHashMap<>();

    private List<ShuShanLiLianConfig> liLianConfigList = new ArrayList<>();
    private Map<Integer, ShuShanLiLianConfig> liLianConfigMap = new ConcurrentHashMap<>();

    private List<ShuShanEventConfig> eventConfigList = new ArrayList<>();
    private Map<Integer, ShuShanEventConfig> eventConfigMap = new ConcurrentHashMap<>();
    private Map<Integer, List<ShuShanEventConfig>> eventTypeConfigMap = new ConcurrentHashMap<>();

    private List<ShuShanRewardConfig> liLianEncounterConfigList = new ArrayList<>();
    /**
     * 历练遭遇奖励 k：历练级别 k:仙力类型 v：遭遇集合
     */
    private Map<Integer, Map<Integer, List<ShuShanRewardConfig>>> liLianEncounterConfigMap = new ConcurrentHashMap<>();

    /**
     * 山门免费刷新次数上限
     */
    private int SHUSHAN_SHANMEN_SHUA_MAX;
    /**
     * 山门免费刷新次数恢复CD
     */
    private int SHUSHAN_SHANMEN_SHUA_CD;
    /**
     * 山门免费刷新次数恢复值
     */
    private int SHUSHAN_SHANMEN_SHUA_NUM;
    /**
     * 刷新元宝消耗（购买次数取配置个数）
     */
    private String SHUSHAN_SHANMEN_SHUA_COST_MONEY;

    private List<Integer> costGoldList = new ArrayList<>();

    /**
     * 前n次刷新的弟子品质
     */
    private String SHUSHAN_SHANMEN_NEW_SHUA;

    /**
     * 前n次刷新的弟子品质
     */
    private List<Integer> randomDiscipleQualityList = new ArrayList<>();

    /**
     * 弟子品质；保底次数|弟子品质；保底次数
     */
    private String SHUSHAN_SHANMEN_SHUA_BAODI;

    private Map<Integer, Integer> baoDiMap = new HashMap<>();

    /**
     * 弟子五维图：单轴数值上限
     */
    private int SHUSHAN_STUDENT_MAX_VALUE;
    /**
     * 弟子尝试修行时间间隔（秒）(平庸|良好|卓越|天才|妖孽)
     */
    private String SHUSHAN_STUDENT_LEARN_CD;

    private Map<Integer, Integer> learnCDMap = new HashMap<>();

    /**
     * 初始仙力区间对应弟子品质
     */
    private String SHUSHAN_STUDENT_POWER_QUILT;

    /**
     * 品质对应的 仙力区间
     */
    private Map<Integer, List<Integer>> powerQuiltMap = new HashMap<>();

    /**
     * 品质对应的仙力 list 0：品质id 1 仙力区间
     */
    private List<Object[]> powerQuiltList = new ArrayList<>();

    /**
     * 修行令使用后立即学习次数
     */
    private int SHUSHAN_STUDY_TOKEN_ADDNUM;

    /**
     * 修行令道具id=消耗数量，用于快速修行
     */
    private String SHUSHAN_STUDY_TOKEN_ID;

    /**
     * 令牌道具id
     */
    private int SHUSHAN_ITEM_ID_TOKEN;
    /**
     * 通用兑换商店积分配置，无积分道具则填0
     */
    private int EXCHANGE_SCORE_ITEM_ID;
    /**
     * 新手引导后获得奖励
     */
    private String SHUSHAN_NEWGUIDE_REWARD;

    /**
     * 宗门名字长度最大值
     */
    private int SHUSHAN_NAME_LENGTH_LIMIT;

    /**
     * 二选一随机事件的出现时间间隔（分钟）
     */
    private int SHUSHAN_EVENT_DTIME;

    /**
     * 离线收益窗口弹出时间限制（min）
     */
    private int SHUSHAN_OFF_TIME_LIMIT;

    /**
     * 弟子仙力分配权重计算系数：保底最小值
     */
    private int SHUSHAN_SHANMEN_SHUA_PARAM_BASE;
    /**
     * 弟子仙力分配权重计算系数：保底浮动区间
     */
    private int SHUSHAN_SHANMEN_SHUA_PARAM_F;
    /**
     * 弟子仙力分配权重计算系数：扩大系数1
     */
    private int SHUSHAN_SHANMEN_SHUA_PARAM_EX_1;
    /**
     * 弟子仙力分配权重计算系数：扩大系数2
     */
    private int SHUSHAN_SHANMEN_SHUA_PARAM_EX_2;

    /**
     * 声望道具id
     */
    private int SHUSHAN_EXP_ID;

    /**
     * 解析配置
     *
     * @param activityConfigMap
     */
    public void parseConfig(Map<String, ActivityConfig> activityConfigMap) {
        SHUSHAN_SHANMEN_SHUA_MAX = activityConfigMap.get(eActivityConfigType.SHUSHAN_SHANMEN_SHUA_MAX.getName()).getIntValue();
        SHUSHAN_SHANMEN_SHUA_CD = activityConfigMap.get(eActivityConfigType.SHUSHAN_SHANMEN_SHUA_CD.getName()).getIntValue();
        SHUSHAN_SHANMEN_SHUA_NUM = activityConfigMap.get(eActivityConfigType.SHUSHAN_SHANMEN_SHUA_NUM.getName()).getIntValue();
//        SHUSHAN_SHANMEN_SHUA_COST_MONEY = activityConfigMap.get(eActivityConfigType.SHUSHAN_SHANMEN_SHUA_COST_MONEY.getName()).getValue();
        SHUSHAN_STUDENT_MAX_VALUE = activityConfigMap.get(eActivityConfigType.SHUSHAN_STUDENT_MAX_VALUE.getName()).getIntValue();
        SHUSHAN_STUDENT_LEARN_CD = activityConfigMap.get(eActivityConfigType.SHUSHAN_STUDENT_LEARN_CD.getName()).getValue();
        SHUSHAN_STUDENT_POWER_QUILT = activityConfigMap.get(eActivityConfigType.SHUSHAN_STUDENT_POWER_QUILT.getName()).getValue();
        SHUSHAN_STUDY_TOKEN_ADDNUM = activityConfigMap.get(eActivityConfigType.SHUSHAN_STUDY_TOKEN_ADDNUM.getName()).getIntValue();
        SHUSHAN_STUDY_TOKEN_ID = activityConfigMap.get(eActivityConfigType.SHUSHAN_STUDY_TOKEN_ID.getName()).getValue();
        SHUSHAN_ITEM_ID_TOKEN = activityConfigMap.get(eActivityConfigType.SHUSHAN_ITEM_ID_TOKEN.getName()).getIntValue();
        EXCHANGE_SCORE_ITEM_ID = activityConfigMap.get(eActivityConfigType.EXCHANGE_SCORE_ITEM_ID.getName()).getIntValue();
        SHUSHAN_NEWGUIDE_REWARD = activityConfigMap.get(eActivityConfigType.SHUSHAN_NEWGUIDE_REWARD.getName()).getValue();
        SHUSHAN_NAME_LENGTH_LIMIT = activityConfigMap.get(eActivityConfigType.SHUSHAN_NAME_LENGTH_LIMIT.getName()).getIntValue();
        SHUSHAN_EVENT_DTIME = activityConfigMap.get(eActivityConfigType.SHUSHAN_EVENT_DTIME.getName()).getIntValue();
        SHUSHAN_OFF_TIME_LIMIT = activityConfigMap.get(eActivityConfigType.SHUSHAN_OFF_TIME_LIMIT.getName()).getIntValue();
        SHUSHAN_SHANMEN_NEW_SHUA = activityConfigMap.get(eActivityConfigType.SHUSHAN_SHANMEN_NEW_SHUA.getName()).getValue();
        SHUSHAN_SHANMEN_SHUA_BAODI = activityConfigMap.get(eActivityConfigType.SHUSHAN_SHANMEN_SHUA_BAODI.getName()).getValue();
        SHUSHAN_SHANMEN_SHUA_PARAM_BASE = activityConfigMap.get(eActivityConfigType.SHUSHAN_SHANMEN_SHUA_PARAM_BASE.getName()).getIntValue();
        SHUSHAN_SHANMEN_SHUA_PARAM_F = activityConfigMap.get(eActivityConfigType.SHUSHAN_SHANMEN_SHUA_PARAM_F.getName()).getIntValue();
        SHUSHAN_SHANMEN_SHUA_PARAM_EX_1 = activityConfigMap.get(eActivityConfigType.SHUSHAN_SHANMEN_SHUA_PARAM_EX_1.getName()).getIntValue();
        SHUSHAN_SHANMEN_SHUA_PARAM_EX_2 = activityConfigMap.get(eActivityConfigType.SHUSHAN_SHANMEN_SHUA_PARAM_EX_2.getName()).getIntValue();
        SHUSHAN_EXP_ID = activityConfigMap.get(eActivityConfigType.SHUSHAN_EXP_ID.getName()).getIntValue();


        // 解析配置
//        costGoldList = StringUtils.stringToIntegerList(SHUSHAN_SHANMEN_SHUA_COST_MONEY, "\\|");
        randomDiscipleQualityList = StringUtils.stringToIntegerList(SHUSHAN_SHANMEN_NEW_SHUA, ";");

        List<String> baoDiList = StringUtils.stringToStringList(SHUSHAN_SHANMEN_SHUA_BAODI, "\\|");
        baoDiList.forEach(e -> {
            List<Integer> list = StringUtils.stringToIntegerList(e, ";");
            baoDiMap.put(list.get(0), list.get(1));
        });

        List<Integer> learnCDList = StringUtils.stringToIntegerList(SHUSHAN_STUDENT_LEARN_CD, "\\|");
        for (int i = 0; i < learnCDList.size(); i++) {
            learnCDMap.put(i, learnCDList.get(i));
        }

        List<String> tempPowerQuiltList = StringUtils.stringToStringList(SHUSHAN_STUDENT_POWER_QUILT, "\\|");
        tempPowerQuiltList.forEach(e -> {
            List<Integer> list = StringUtils.stringToIntegerList(e, ";");
            int quilt = list.remove(0);
            powerQuiltMap.put(quilt, list);

            Object[] objects = new Object[2];
            objects[0] = quilt;
            objects[1] = list;
            powerQuiltList.add(objects);
        });


        for (ShuShanBuildConfig item : buildConfigList) {
            buildConfigMap.put(item.getId(), item);
            Map<Integer, ShuShanBuildConfig> map = typeLevelBuildMap.get(item.getType());
            if (map == null) {
                map = new HashMap<>();
                typeLevelBuildMap.put(item.getType(), map);
            }
            map.put(item.getLevel(), item);
            List<ShuShanBuildConfig> list = typeLevelBuildListMap.get(item.getType());
            if (list == null) {
                list = new ArrayList<>();
                typeLevelBuildListMap.put(item.getType(), list);
            }
            list.add(item);
            if (item.getType() <= eShuShanBuildType.type_5.getType()) {
                List<Integer> typeLevelSkillList = typeLevelSkillListMap.get(item.getType());
                if (typeLevelSkillList == null) {
                    typeLevelSkillList = new ArrayList<>();
                    typeLevelSkillListMap.put(item.getType(), typeLevelSkillList);
                }
                typeLevelSkillList.add(Integer.valueOf(item.getParam()));
            }
        }

        for (ShuShanSkillConfig item : skillConfigList) {
            skillConfigMap.put(item.getId(), item);
            List<ShuShanSkillConfig> list = skillTypeConfigMap.get(item.getType());
            if (list == null) {
                list = new ArrayList<>();
                skillTypeConfigMap.put(item.getType(), list);
            }
            list.add(item);

            Map<Integer, Map<Integer, ShuShanSkillConfig>> map = typeLevelConfigMap.get(item.getType());
            if (map == null) {
                map = new HashMap<>();
                typeLevelConfigMap.put(item.getType(), map);
            }
            Map<Integer, ShuShanSkillConfig> levelMap = map.get(item.getLittleType());
            if (levelMap == null) {
                levelMap = new HashMap<>();
                map.put(item.getLittleType(), levelMap);
            }
            levelMap.put(item.getLevel(), item);

            Map<Integer, List<ShuShanSkillConfig>> typeLevelMap = typeLevelConfigListMap.get(item.getType());
            if(typeLevelMap == null){
                typeLevelMap = new HashMap<>();
                typeLevelConfigListMap.put(item.getType(), typeLevelMap);
            }
            List<ShuShanSkillConfig> typeLevelList = typeLevelMap.get(item.getLittleType());
            if(typeLevelList == null){
                typeLevelList = new ArrayList<>();
                typeLevelMap.put(item.getLittleType(), typeLevelList);
            }
            typeLevelList.add(item);
        }

        // eventTypeConfigMap
        for (ShuShanEventConfig item : eventConfigList) {
            eventConfigMap.put(item.getId(), item);

            List<ShuShanEventConfig> list = eventTypeConfigMap.get(item.getType());
            if (list == null) {
                list = new ArrayList<>();
                eventTypeConfigMap.put(item.getType(), list);
            }
            list.add(item);
        }

        for (ShuShanLiLianConfig item : liLianConfigList) {
            liLianConfigMap.put(item.getId(), item);
        }

        // 遭遇奖励
        for (ShuShanRewardConfig item : liLianEncounterConfigList) {
            Map<Integer, List<ShuShanRewardConfig>> map = liLianEncounterConfigMap.get(item.getLevel());
            if (map == null) {
                map = new HashMap<>();
                liLianEncounterConfigMap.put(item.getLevel(), map);
            }
            List<ShuShanRewardConfig> list = map.get(item.getPowerType());
            if (list == null) {
                list = new ArrayList<>();
                map.put(item.getPowerType(), list);
            }
            list.add(item);
        }
    }

    public int getSHUSHAN_SHANMEN_SHUA_MAX() {
        return SHUSHAN_SHANMEN_SHUA_MAX;
    }

    public int getSHUSHAN_SHANMEN_SHUA_CD() {
        return SHUSHAN_SHANMEN_SHUA_CD;
    }

    public int getSHUSHAN_SHANMEN_SHUA_NUM() {
        return SHUSHAN_SHANMEN_SHUA_NUM;
    }

    public String getSHUSHAN_SHANMEN_SHUA_COST_MONEY() {
        return SHUSHAN_SHANMEN_SHUA_COST_MONEY;
    }

    public int getSHUSHAN_STUDENT_MAX_VALUE() {
        return SHUSHAN_STUDENT_MAX_VALUE;
    }

    public String getSHUSHAN_STUDENT_LEARN_CD() {
        return SHUSHAN_STUDENT_LEARN_CD;
    }

    public String getSHUSHAN_STUDENT_POWER_QUILT() {
        return SHUSHAN_STUDENT_POWER_QUILT;
    }

    public int getSHUSHAN_STUDY_TOKEN_ADDNUM() {
        return SHUSHAN_STUDY_TOKEN_ADDNUM;
    }

    public int getSHUSHAN_ITEM_ID_TOKEN() {
        return SHUSHAN_ITEM_ID_TOKEN;
    }

    public int getEXCHANGE_SCORE_ITEM_ID() {
        return EXCHANGE_SCORE_ITEM_ID;
    }

    public String getSHUSHAN_NEWGUIDE_REWARD() {
        return SHUSHAN_NEWGUIDE_REWARD;
    }

    public String getSHUSHAN_STUDY_TOKEN_ID() {
        return SHUSHAN_STUDY_TOKEN_ID;
    }

    public int getSHUSHAN_EVENT_DTIME() {
        return SHUSHAN_EVENT_DTIME;
    }

    public int getSHUSHAN_NAME_LENGTH_LIMIT() {
        return SHUSHAN_NAME_LENGTH_LIMIT;
    }

    public int getSHUSHAN_OFF_TIME_LIMIT() {
        return SHUSHAN_OFF_TIME_LIMIT;
    }

    public int getSHUSHAN_SHANMEN_SHUA_PARAM_BASE() {
        return SHUSHAN_SHANMEN_SHUA_PARAM_BASE;
    }

    public int getSHUSHAN_SHANMEN_SHUA_PARAM_F() {
        return SHUSHAN_SHANMEN_SHUA_PARAM_F;
    }

    public int getSHUSHAN_SHANMEN_SHUA_PARAM_EX_1() {
        return SHUSHAN_SHANMEN_SHUA_PARAM_EX_1;
    }

    public int getSHUSHAN_SHANMEN_SHUA_PARAM_EX_2() {
        return SHUSHAN_SHANMEN_SHUA_PARAM_EX_2;
    }

    public int getSHUSHAN_EXP_ID() {
        return SHUSHAN_EXP_ID;
    }

    public List<ShuShanBuildConfig> getBuildConfigList() {
        return buildConfigList;
    }

    public void setBuildConfigList(List<ShuShanBuildConfig> buildConfigList) {
        this.buildConfigList = buildConfigList;
    }

    public Map<Integer, ShuShanBuildConfig> getBuildConfigMap() {
        return buildConfigMap;
    }

    public void setBuildConfigMap(Map<Integer, ShuShanBuildConfig> buildConfigMap) {
        this.buildConfigMap = buildConfigMap;
    }

    public List<ShuShanSkillConfig> getSkillConfigList() {
        return skillConfigList;
    }

    public void setSkillConfigList(List<ShuShanSkillConfig> skillConfigList) {
        this.skillConfigList = skillConfigList;
    }

    public Map<Integer, ShuShanSkillConfig> getSkillConfigMap() {
        return skillConfigMap;
    }

    public void setSkillConfigMap(Map<Integer, ShuShanSkillConfig> skillConfigMap) {
        this.skillConfigMap = skillConfigMap;
    }

    public List<ShuShanLiLianConfig> getLiLianConfigList() {
        return liLianConfigList;
    }

    public void setLiLianConfigList(List<ShuShanLiLianConfig> liLianConfigList) {
        this.liLianConfigList = liLianConfigList;
    }

    public Map<Integer, ShuShanLiLianConfig> getLiLianConfigMap() {
        return liLianConfigMap;
    }

    public void setLiLianConfigMap(Map<Integer, ShuShanLiLianConfig> liLianConfigMap) {
        this.liLianConfigMap = liLianConfigMap;
    }

    public List<ShuShanEventConfig> getEventConfigList() {
        return eventConfigList;
    }

    public void setEventConfigList(List<ShuShanEventConfig> eventConfigList) {
        this.eventConfigList = eventConfigList;
    }

    public Map<Integer, ShuShanEventConfig> getEventConfigMap() {
        return eventConfigMap;
    }

    public void setEventConfigMap(Map<Integer, ShuShanEventConfig> eventConfigMap) {
        this.eventConfigMap = eventConfigMap;
    }

    public Map<Integer, Map<Integer, ShuShanBuildConfig>> getTypeLevelBuildMap() {
        return typeLevelBuildMap;
    }

    public Map<Integer, List<ShuShanBuildConfig>> getTypeLevelBuildListMap() {
        return typeLevelBuildListMap;
    }

    public List<Integer> getCostGoldList() {
        return costGoldList;
    }

    public Map<Integer, Integer> getLearnCDMap() {
        return learnCDMap;
    }

    public Map<Integer, List<Integer>> getTypeLevelSkillListMap() {
        return typeLevelSkillListMap;
    }

    public Map<Integer, List<ShuShanEventConfig>> getEventTypeConfigMap() {
        return eventTypeConfigMap;
    }

    public Map<Integer, List<Integer>> getPowerQuiltMap() {
        return powerQuiltMap;
    }

    public Map<Integer, List<ShuShanSkillConfig>> getSkillTypeConfigMap() {
        return skillTypeConfigMap;
    }

    public List<Object[]> getPowerQuiltList() {
        return powerQuiltList;
    }

    public List<ShuShanRewardConfig> getLiLianEncounterConfigList() {
        return liLianEncounterConfigList;
    }

    public void setLiLianEncounterConfigList(List<ShuShanRewardConfig> liLianEncounterConfigList) {
        this.liLianEncounterConfigList = liLianEncounterConfigList;
    }

    public Map<Integer, Map<Integer, List<ShuShanRewardConfig>>> getLiLianEncounterConfigMap() {
        return liLianEncounterConfigMap;
    }

    public void setLiLianEncounterConfigMap(Map<Integer, Map<Integer, List<ShuShanRewardConfig>>> liLianEncounterConfigMap) {
        this.liLianEncounterConfigMap = liLianEncounterConfigMap;
    }

    public List<Integer> getRandomDiscipleQualityList() {
        return randomDiscipleQualityList;
    }

    public Map<Integer, Integer> getBaoDiMap() {
        return baoDiMap;
    }

    public static String getSHUSHAN_SECT_NAME() {
        return SHUSHAN_SECT_NAME;
    }

    public Map<Integer, Map<Integer, Map<Integer, ShuShanSkillConfig>>> getTypeLevelConfigMap() {
        return typeLevelConfigMap;
    }

    public Map<Integer, Map<Integer, List<ShuShanSkillConfig>>> getTypeLevelConfigListMap() {
        return typeLevelConfigListMap;
    }

    /**
     * 获取该格子的遭遇配置
     */
    public List<ShuShanRewardConfig> getActivityConditionInfoList(int gridId) {
        ShuShanLiLianConfig liLianConfig = liLianConfigMap.get(gridId);
        if (liLianConfig == null) {
            return null;
        }
        Map<Integer, List<ShuShanRewardConfig>> map = liLianEncounterConfigMap.get(liLianConfig.getReward());
        if (map == null || map.size() <= 0) {
            return null;
        }
        return map.get(liLianConfig.getSpLimit());
    }

}
